package com.aaa.sso.controller;

import com.aaa.common.util.Result;
import com.aaa.common.util.ResultStatus;
import com.aaa.sso.service.AuthService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author Xiujie Yu
 * @Date 2021-01-21
 * @Time 14:37
 */
@RestController
@RequestMapping("userLogin")
@ApiOperation("userLoginController")
public class UserLoginController {

    @Resource(name = "authUserService")
    private AuthService authService;

    /**
     * 功能描述:用户或会员登陆认证
     *
     * @param userName String
     * @param password String
     * @return com.aaa.common.util.Result
     */
    @GetMapping("auth")
    public Result<Map<String, Object>> authUser(String userName, String password) {
        return this.authService.authUserMember(userName, password);
    }

    /**
     * 功能描述:验证Token方法
     *
     * @param token String
     * @return boolean
     */
    @GetMapping("checkToken")
    public boolean checkToken(@RequestHeader("token") String token) {
        return this.authService.checkToken(token);
    }

    /**
     * 修改用户的密码
     *
     * @param userName 用户名
     * @param oldPassword 旧密码
     * @param newPassword 新密码
     * @return boolean
     */
    @GetMapping("updateUserPassword")
    public Result<Boolean> updateUserPassword(String userName,String oldPassword, String newPassword) {
        System.out.println(userName+"    old:"+oldPassword+"   new:"+newPassword);
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.authService.updateUserPassword(userName,oldPassword, newPassword));
    }

}
